<!--经纪公司结佣申请-- 详情-->
<template>
  <div class="brokerCompanyDetail">
    <el-breadcrumb separator="/" class="bread-title">
      <el-breadcrumb-item :to="{ path: '/brokerCompany' }">经纪公司结佣申请</el-breadcrumb-item>
      <el-breadcrumb-item v-if="seeOrToExamine == 1">查看详情</el-breadcrumb-item>
      <el-breadcrumb-item v-else>审核详情</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="item">
      <p class="textTitle">经纪公司佣金信息</p>
      <div class="item-group">
        <p>公司名称：{{info.companyName}}</p>
        <p>申请结佣金额：{{info.brokerAmount}}元</p>
        <p v-if="seeOrToExamine == 2 && role">
          税率：
          <el-input
            @input="oninput"
            size="mini"
            style="width:150px;display:inline-block"
            v-model="ruleForm.taxBrokerageRate"
          ></el-input>
          <span>%</span>
        </p>
        <p v-else>税率：{{info.taxBrokerageRate}}%</p>
        <p>税金: {{info.taxBrokerage}}元</p>
        <p>应付款金额: {{info.payBrokerage}}元</p>
      </div>
    </div>
    <div class="item" v-if="seeOrToExamine == 2 && role">
      <p class="textTitle">结算付款信息</p>
      <el-form :model="ruleForm" :inline="true" :rules="rules" ref="ruleForm" label-width="120px">
        <el-form-item label="票据方式：" prop="billWay">
          <el-select v-model="ruleForm.billWay" placeholder="请选择">
            <el-option label="无" :value="1"></el-option>
            <el-option label="发票" :value="2"></el-option>
            <el-option label="收据" :value="3"></el-option>
            <el-option label="发票欠收单" :value="4"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="付款结算方式：" prop="payType">
          <el-select v-model="ruleForm.payType" placeholder="请选择" @change="changePayType">
            <el-option label="通过银企直连付款（对公）" :value="1"></el-option>
            <el-option label="通过银企直连付款（对私）" :value="2"></el-option>
            <el-option label="转账" :value="3"></el-option>
            <el-option label="E-Bill付款" :value="4" v-show="ebillCheck"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="计税方式：" prop="taxCalculationWay">
          <el-select v-model="ruleForm.taxCalculationWay" placeholder="请选择">
            <el-option label="一般" :value="1"></el-option>
            <el-option label="简易" :value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否有发票：" prop="billHave">
          <el-select @change="billHaveChange" v-model="ruleForm.billHave" placeholder="请选择">
            <el-option label="是" :value="1"></el-option>
            <el-option label="否" :value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item v-if="isShowBill" label="发票类型：" prop="billType">
          <el-select v-model="ruleForm.billType" placeholder="请选择">
            <el-option label="普通发票" :value="1"></el-option>
            <el-option label="增值税专用发票" :value="2"></el-option>
            <el-option label="其他可抵扣发票" :value="3"></el-option>
            <el-option label="其他票据" :value="4"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否委托收款：">
          <el-radio-group v-model="ruleForm.receiptType">
            <el-radio disabled :label="0">否</el-radio>
            <el-radio disabled :label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="付款摘要：">
          <el-input style="width:300px" maxlength="150" v-model="ruleForm.payNote" placeholder="请输入"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <div v-else class="item">
      <p class="textTitle">结算付款信息</p>
      <table>
        <tr>
          <td>票据方式</td>
          <td>{{billWay}}</td>
          <td>付款结算方式</td>
          <td>{{payType}}</td>
          <td>计税方式</td>
          <td>{{info.taxCalculationWay == 1 ? '一般' : '简易'}}</td>
        </tr>
        <tr>
          <td>是否有发票</td>
          <td>{{info.billHave == 1 ? '是' : '否'}}</td>
          <td v-if="info.billHave == 1">发票类型</td>
          <td v-if="info.billHave == 1">{{billType}}</td>
          <td>是否委托收款</td>
          <td>{{info.receiptType == 0 ? '否' : '是'}}</td>
        </tr>
        <tr>
          <td>付款摘要</td>
          <td style="text-align:left" colspan="5">{{info.payNote}}</td>
        </tr>
      </table>
    </div>
    <div class="item" v-if="info.receiptType == 0">
      <p class="textTitle">收款账号信息</p>
      <table>
        <tr>
          <td>收款公司</td>
          <td>{{info.companyName}}</td>
          <td>收款账号</td>
          <td>{{info.companyCard}}</td>
          <td>开卡省-市</td>
          <td>{{info.recProvinceName}} — {{info.recCityName}}</td>
        </tr>
        <tr>
          <td>开户支行</td>
          <td>{{info.bankBranchName}}</td>
          <td>联行号</td>
          <td>{{info.bankBranchNum}}</td>
          <td>地区代码</td>
          <td>{{info.openCode}}</td>
        </tr>
        <tr>
          <td>纳税人识别号</td>
          <td>{{info.recTaxpayerNumber}}</td>
          <td>—</td>
          <td>—</td>
          <td>—</td>
          <td>—</td>
        </tr>
      </table>
    </div>
    <div class="item" v-else>
      <el-tabs style="margin-top:15px;" v-model="activeName">
        <el-tab-pane label="（委托）收款账号信息" name="first">
          <table>
            <tr>
              <td>收款公司</td>
              <td>{{info.entrustCompanyName}}</td>
              <td>收款账号</td>
              <td>{{info.entrustBankCard}}</td>
              <td>开卡省-市</td>
              <td>{{info.entrustRecProvinceName}} — {{info.entrustRecCityName}}</td>
            </tr>
            <tr>
              <td>开户支行</td>
              <td>{{info.entrustBankBranchName}}</td>
              <td>联行号</td>
              <td>{{info.entrustBranchNum}}</td>
              <td>地区代码</td>
              <td>{{info.entrustOpenCode}}</td>
            </tr>
          </table>
        </el-tab-pane>
        <el-tab-pane label="（原）收款账号信息" name="second">
          <table>
            <tr>
              <td>收款公司</td>
              <td>{{info.companyName}}</td>
              <td>收款账号</td>
              <td>{{info.companyCard}}</td>
              <td>开卡省-市</td>
              <td>{{info.recProvinceName}} — {{info.recCityName}}</td>
            </tr>
            <tr>
              <td>开户支行</td>
              <td>{{info.bankBranchName}}</td>
              <td>联行号</td>
              <td>{{info.bankBranchNum}}</td>
              <td>地区代码</td>
              <td>{{info.openCode}}</td>
            </tr>
          </table>
        </el-tab-pane>
      </el-tabs>
    </div>
    <div class="item" style="position:relative">
      <p class="textTitle">付款账号信息</p>
      <p v-if="seeOrToExamine == 2 && role" @click="dialogPaymentAccount" class="Payment">
        <i class="el-icon-edit-outline"></i>修改付款账号
      </p>
      <table>
        <tr>
          <td>付款公司</td>
          <td>{{info.payerCompany}}</td>
          <td>付款账号</td>
          <td>{{info.payerAccount}}</td>
          <td>开户支行</td>
          <td>{{info.payerBranchBankName}}</td>
        </tr>
        <tr>
          <td>纳税人识别号</td>
          <td>{{info.payerIdentityNum}}</td>
          <td>—</td>
          <td>—</td>
          <td>—</td>
          <td>—</td>
        </tr>
      </table>
    </div>
    <div class="moneyInfo" v-show="ruleForm.payType == 4 || payType == 'E-Bill付款'">
      <p>
        <span :class="money==1 && seeOrToExamine == 1?'moneyInfo-color financingInfo':'financingInfo'" @click="getFinancingInfo(1)">融资结算信息</span>
        <span :class="money==2?'moneyInfo-color financingInfo':'financingInfo'" 
        @click="getFinancingInfo(2)" v-show="seeOrToExamine == 1">E-Bill信息</span>
      </p>
      <table v-show="money==1 || seeOrToExamine == 2">
        <tr>
          <td class="td-name">本次融资金额</td>
          <td class="td-content">{{financeProductInfo.financialAmount?formatMoney(financeProductInfo.financialAmount)+'元':''}}</td>
        </tr>
        <tr>
          <td class="td-name">金融产品名称</td>
          <td class="td-content">
            <span v-show="seeOrToExamine == 1 || !role">{{financeProductInfo.financialProductName}}</span>
            <el-select v-show="seeOrToExamine == 2 && role" v-model="financeProductId" placeholder="请选择" size="small" @change="changefinanceProduct">
              <el-option :label="item.financialSceneName" :value="item.financialSceneId" v-for="(item,index) in financeProductList"  :key='index' ></el-option>
            </el-select>
          </td>
        </tr>
        <tr>
          <td class="td-name">预估融资利率</td>
          <td class="td-content td-contentName">
            <div>{{financeProductInfo.interestRate?financeProductInfo.interestRate+'%':''}}</div>
            <div class="minddle" v-show="bearRate.length">其中：</div>
            <div>
              <p v-for="(item,index) in bearRate" :key="index">
                <span>{{item.applyRoleName?item.applyRoleName+'：':''}}</span>
                <span>{{item.shareInterestRate?item.shareInterestRate+'%':''}}</span>
              </p>
            </div>
          </td>
        </tr>
        <tr>
          <td class="td-name">融资可用额度</td>
          <td class="td-content">{{financeProductInfo.availableAmount?formatMoney(financeProductInfo.availableAmount)+'元':''}}</td>
        </tr>
        <tr>
          <td class="td-name">预估利息</td>
          <td class="td-content">{{financeProductInfo.interest?formatMoney(financeProductInfo.interest)+'元':''}}</td>
        </tr>
        <tr>
          <td class="td-name">到期预计本息金额</td>
          <td class="td-content">{{financeProductInfo.principalAndInterest?formatMoney(financeProductInfo.principalAndInterest)+'元':''}}</td>
        </tr>
        <tr>
          <td class="td-name">账期</td>
          <td class="td-content">
            <span>{{financeProductInfo.acctPeriod?financeProductInfo.acctPeriod+'天':''}}</span>
          </td>
        </tr>
        <tr>
          <td class="td-name">预计还款日期</td>
          <td class="td-content">{{financeProductInfo.repayDate}}</td>
        </tr>
        <tr>
          <td class="td-name">付款类型</td>
          <td class="td-content">{{financeProductInfo.billPayType == 5 ? '佣金款':''}}</td>
        </tr>
      </table>
      <table v-show="money==2 && seeOrToExamine !=2">
        <tr>
          <td class="td-name">资产编号</td>
          <td class="td-content">{{financeProductInfo.assetCode}}</td>
        </tr>
        <tr>
          <td class="td-name">资产生效日期</td>
          <td class="td-content">{{financeProductInfo.validDate}}</td>
        </tr>
        <tr>
          <td class="td-name">资产到期日</td>
          <td class="td-content">{{financeProductInfo.expireDate}}</td>
        </tr>
        
      </table>
    </div>
    <div class="item">
      <p class="textTitle">附件信息</p>
      <div class="item-group fileStyle">
        <p>1.发票信息</p>
        <span>快递公司：{{info.courierCompany}}</span>
        <span>快递单号：{{info.courierCode}}</span>
        <p style="line-height:60px"></p>
        <viewer :images="img1">
          <img v-for="src in img1" :src="src" :key="src.id" />
        </viewer>
        <ul class="pdfStyle">
          <li v-for="item in pdf1" :key="item.id">
            <a @click="openPdf(item.url)" href="#">{{item.name}} 点击预览（下载）</a>
          </li>
        </ul>
      </div>
      <div class="item-group fileStyle">
        <p>
          <span>2.渠道合作通知函/合作协议</span>
          <el-button v-if="channelNotificationLetter" @click="letterClick" type="text">刷新</el-button>
        </p>
        <viewer :images="img2">
          <img v-for="src in img2" :src="src" :key="src.id" />
        </viewer>
        <ul class="pdfStyle">
          <li v-for="item in pdf2" :key="item.id">
            <a @click="openPdf(item.url)" href="#">{{item.name}} 点击预览（下载）</a>
          </li>
        </ul>
      </div>
      <div class="item-group fileStyle">
        <p>3.佣金确认表及其他相关附件</p>
        <viewer :images="img3">
          <img v-for="src in img3" :src="src" :key="src.id" />
        </viewer>
        <ul class="pdfStyle">
          <li v-for="item in pdf3" :key="item.id">
            <a @click="openPdf(item.url)" href="#">{{item.name}} 点击预览（下载）</a>
          </li>
        </ul>
      </div>
      <div class="item-group fileStyle" v-if="info.receiptType == 1">
        <p>4.委托收款书</p>
        <viewer :images="img5">
          <img v-for="src in img5" :src="src" :key="src.id" />
        </viewer>
        <ul>
          <li v-for="item in pdf5" :key="item.id">
            <a @click="openPdf(item.url)" href="#">{{item.name}} 点击预览（下载）</a>
          </li>
        </ul>
      </div>
      <div class="item-group fileStyle">
        <p v-if="info.receiptType == 1">5.其他附件</p>
        <p v-else>4.其他附件</p>
        <upload
          ref="upload"
          :multiple="true"
          :accept="'.jpg,.jpeg,.png,.pdf,.JPG,.JPEG,'"
          :fileList="fileList"
          v-if="seeOrToExamine == 2 && role"
        ></upload>
        <div v-else>
          <viewer :images="img4">
            <img v-for="(src,index) in img4" :src="src" :key="index" />
          </viewer>
          <ul class="pdfStyle">
            <li v-for="(item,index) in pdf4" :key="index">
              <a @click="openPdf(item.url)" href="#">{{index+1}}.{{item.name}} 点击预览（下载）</a>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <div class="items">
      <p class="textTitle">订单</p>
      <el-table :data="tableData" border>
        <el-table-column align="center" :index="indexFun" type="index" label="序号"></el-table-column>
        <template v-for="colConfig in colConfigs">
          <el-table-column align="center" v-bind="colConfig" :key="colConfig.id"></el-table-column>
        </template>
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="orderDetail(scope.row.orderId)"
              v-if="scope.$index != 0"
            >订单详情</el-button>
            <span v-else>——</span>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        style="margin-top:15px;"
        layout="total, sizes, prev, pager, next"
        :current-page.sync="form.pageNum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="form.pageSize"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :total="total"
      ></el-pagination>
    </div>
    <div class="item">
      <p class="textTitle">结佣审批流程</p>
      <div class="technologicalProcess">
        <el-steps align-center :active="flowChart">
          <el-step title="提交审核"></el-step>
          <el-step title="运营审核"></el-step>
          <el-step title="财务审核"></el-step>
          <el-step title="H3审核"></el-step>
          <el-step title="保理审核" v-if="(financeProductId || ruleForm.payType == 4) && (payType == 'E-Bill付款')"></el-step>
        </el-steps>
      </div>
    </div>
    <div class="items" v-if="seeOrToExamine == 1 || (seeOrToExamine == 2 && again)">
      <p class="textTitle">审批记录</p>
      <el-table :data="records" border style="width: 100%">
        <el-table-column align="center" prop="system" label="系统"></el-table-column>
        <el-table-column align="center" prop="operationText" label="操作"></el-table-column>
        <el-table-column align="center" prop="reason" label="审批意见"></el-table-column>
        <el-table-column align="center" prop="operatorName" label="操作人"></el-table-column>
        <el-table-column align="center" prop="operatorRoleText" label="角色"></el-table-column>
        <el-table-column align="center" :formatter="recordsTime" prop="createTime" label="时间"></el-table-column>
      </el-table>
    </div>
    <div class="AudiReason" v-if="seeOrToExamine == 2 && !again">
      <div class="textTitle">审核理由</div>
      <el-input
        maxlength="150"
        type="textarea"
        :autosize="{ minRows: 3, maxRows: 7}"
        placeholder="请输入内容"
        v-model="reason"
      ></el-input>
      <span class="resasonNum">{{reason.length}}/{{150 - reason.length}}</span>
      <p style="text-align:center">
        <el-button type="primary" @click="agree">通过</el-button>
        <el-button type="primary" @click="refuse">拒绝</el-button>
      </p>
    </div>
    <div class="AudiReason" v-if="seeOrToExamine == 2 && again">
      <div class="textTitle">调整说明</div>
      <el-input
        maxlength="150"
        type="textarea"
        :autosize="{ minRows: 3, maxRows: 7}"
        placeholder="请输入内容"
        v-model="reason"
      ></el-input>
      <span class="resasonNum">{{reason.length}}/{{150 - reason.length}}</span>
      <p style="text-align:center">
        <el-button type="primary" @click="againSubmit">重新提交</el-button>
        <el-button type="primary" @click="RejectSubmit">驳回</el-button>
        <el-button type="primary" @click="cancelSubmit">取消</el-button>
      </p>
    </div>
    <!--修改付款账号-->
    <el-dialog title="修改付款账号" :visible.sync="dialogTableVisible">
      <el-form :model="PaymentForm" :rules="PaymentRules" ref="PaymentForm" label-width="180px">
        <el-form-item label="数据源：">
          <span>内部法人管理</span>
        </el-form-item>
        <el-form-item label="付款公司：" prop="payerCompanyId">
          <el-select
            filterable
            @change="acountCompanyChange"
            v-model="PaymentForm.payerCompanyId"
            placeholder="请选择"
          >
            <el-option
              v-for="item in paymentCompany"
              :key="item.id"
              :label="item.companyName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="账户：" prop="payerAccountId">
          <el-select
            @change="accountChange"
            filterable
            v-model="PaymentForm.payerAccountId"
            placeholder="请选择"
          >
            <el-option
              v-for="item in account"
              :key="item.id"
              :label="item.bankAccount"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开户行名称（支行）：">
          <span>{{accountData.payerBranchBankName}}</span>
        </el-form-item>
        <el-form-item label="纳税人识别号：">
          <span>{{accountData.payerIdentityNum}}</span>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="accountSubmitForm('PaymentForm')">确定</el-button>
          <el-button @click="accountResetForm('PaymentForm')">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import utils from "@/common/utils";
import api from "@/api/apiPath";
import upload from "@/components/common/Upload";
export default {
  name: "brokerCompanyDetail",
  components: {
    upload
  },
  data() {
    return {
      financeProductInfo:{},
      bearRate:[],
      financeProductList:[],//金融产品列表
      ebillCheck:null,//e-bill付款是否展示
      financeProductId:'',
      accountPeriod:'',
      money:1,
      activeName: "first",
      dialogTableVisible: false,
      isShowBill: false, // 是否显示发票类型
      isShowAccount: true,
      paymentCompany: [],
      account: [], // 账户列表
      PaymentForm: {
        payerCompanyId: "",
        payerAccountId: ""
      },
      // 审核
      ruleForm: {
        billWay: "",
        payType: "",
        taxCalculationWay: "",
        taxBrokerageRate: "", // 税率
        receiptType: 0,
        billHave: "",
        billType: 2,
        payNote: "",
        reason: "",
        // 付款公司信息
        payerCompany: "", // 公司
        payerAccount: "", // 账户
        payerIdentityNum: "", // 纳税人识别号
        payerBranchBankName: "", // 支行名称
        paymentId: "", // 付款方id
        paymentCode: "",
        urlAddress4: [] // 文件数组
      },
      rules: {
        billWay: [
          { required: true, message: "请选择票据方式", trigger: "change" }
        ],
        payType: [
          { required: true, message: "请选择付款结算方式", trigger: "change" }
        ],
        taxCalculationWay: [
          { required: true, message: "请选择计税方式", trigger: "change" }
        ],
        billHave: [
          { required: true, message: "请选择是否有发票", trigger: "change" }
        ],
        billType: [
          { required: true, message: "请选择发票类型", trigger: "change" }
        ]
      },
      PaymentRules: {
        payerCompanyId: [
          { required: true, message: "请选择付款公司", trigger: "change" }
        ],
        payerAccountId: [
          { required: true, message: "请选择账户", trigger: "change" }
        ]
      },
      form: {
        id: "",
        pageNum: 1,
        pageSize: 10
      },
      colConfigs: [
        { prop: "brokerRoleType", label: "角色" },
        { prop: "brokerName", label: "经纪人姓名" },
        { prop: "comBrokerageProportion", label: "分佣比例" },
        { prop: "brokerPhone", label: "经纪人手机号" },
        { prop: "customerName", label: "客户姓名" },
        {
          prop: "customerPhone",
          label: "手机号",
          formatter: this.customerPhone
        },
        { prop: "devName", label: "楼盘名称" },
        { prop: "buildName", label: "楼栋" },
        { prop: "unit", label: "单元" },
        { prop: "cellName", label: "房号" },
        { prop: "nodeName", label: "结佣类别" },
        { prop: "creatTime", label: "时间", formatter: this.initTime },
        { prop: "devAmount", label: "房款" },
        { prop: "dealAmount", label: "成交价" },
        { prop: "shouldAmount", label: "应结佣金额（元）" },
        { prop: "comShouldAmount", label: "经纪公司应结佣金额（元）" }
      ],
      tableData: [],
      total: 0,
      info: {},
      records: [],
      reason: "", // 审核意见
      cash: true,
      brokerType: "",
      brokerPhone: "", // 手机号
      seeOrToExamine: 1, // 查看or 审核 or 重新提交
      role: "", // 角色
      again: false, // 是否是重新提交
      img1: [],
      pdf1: [],
      img2: [],
      pdf2: [],
      img3: [],
      pdf3: [],
      img4: [],
      pdf4: [],
      img5: [],
      pdf5: [],
      fileList: [],
      accountData: {
        payerCompany: "",
        payerIdentityNum: "",
        payerAccount: "",
        payerBranchBankName: "",
        paymentId: "",
        paymentCode: ""
      }
    };
  },
  computed: {
    channelNotificationLetter() {
      if (
        this.info.examineState == 1 &&
        this.seeOrToExamine == 2 &&
        this.role
      ) {
        return true;
      } else {
        return false;
      }
    },
    payType() {
      if (this.info.payType == 1) {
        return "通过银企直连付款（对公）";
      } else if (this.info.payType == 2) {
        return "通过银企直连付款（对私）";
      } else if (this.info.payType == 4) {
        return "E-Bill付款";
      } else {
        return "转账";
      }
    },
    billWay() {
      if (this.info.billWay == 1) {
        return "无";
      } else if (this.info.billWay == 2) {
        return "发票";
      } else if (this.info.billWay == 3) {
        return "收据";
      } else {
        return "发票欠收单";
      }
    },
    billType() {
      if (this.info.billType == 1) {
        return "普通发票";
      } else if (this.info.billType == 2) {
        return "增值税专用发票";
      } else if (this.info.billType == 3) {
        return "其他可抵扣发票";
      } else {
        return "其他票据";
      }
    },
    // 流程图控制
    flowChart() {
      let status = 0;
      if (this.info.examineState == 1) {
        status = 1;
      } else if (this.info.examineState == 2) {
        status = 2;
      } else if (this.info.examineState == 3) {
        status = 3;
      }
      if(this.info.bpmAuditStatus == 2) {
        status = 4
      }
      if(this.info.ebillAuditStatus == 1){
        status = 5
      }
      if(this.info.ebillAuditStatus == 2){
        status = 1
      }
      return status;
    }
  },
  created() {
    // 1 是查看， 2是审核
    this.seeOrToExamine = this.$route.query.num;
    this.again = this.$route.query.again;
    let role = JSON.parse(window.localStorage.getItem("cmsUser")).roleName;
    if (role == "运营人员") {
      this.role = true;
      this.getFinanceProductList()
    } else {
      this.role = false;
    }
    this.form.id = this.$route.query.id;
    this.detail();
    this.orderList();
    this.getEbillCheck();
  },
  methods: {
    changePayType(val){
      this.info.payType = val
    },
    formatMoney(val){
      return utils.formatMoney(val)
    },
    // 获取场景金融产品列表
    getFinanceProductList(){
      this.$axios.post('/financialCenter/financeProduct/sceneList',{
        businessScene:1,
        productType:1,
        devId:this.$route.query.devId,
        applyRole:3,
        fundSideName:'壹链盟'
      }).then(res=>{
        this.financeProductList = res
      })
    },
    changefinanceProduct(val){
      this.getFinancialProductSceneDetail(val)
    },
    // 融资结算信息
    getFinancialProductSceneDetail(val){
      this.$axios.post('/commission/financialSettlement/financialProductSceneDetail',{
        financialSceneId:val,
        applyId:this.$route.query.id
      }).then(res=>{
        this.financeProductInfo = res
        this.bearRate = JSON.parse(this.financeProductInfo.bearRate)
      })
    },
    // E-Bill付款显示校验
    getEbillCheck(){
      this.$axios.get('/commission/company/apply/checkEBillAuthority/'+this.$route.query.id).then(res=>{
        this.ebillCheck = res
      }).catch(error=>{
        console.log(error)
      })
    },
    getFinancingInfo(val){
      this.money = val
    },

    initTime(row, column, cellValue, index) {
      if (index == 0) {
        return "——";
      }
      return utils.getTimeString(row.creatTime);
    },
    // 渠道合作通知函/合作协议 刷新按钮
    letterClick() {
      this.$axios
        .post(api.freshApproach, { applyId: this.info.id })
        .then(res => {
          this.$message({
            type: "success",
            message: "操作成功"
          });
          this.img1 = [];
          this.pdf1 = [];
          this.img2 = [];
          this.img3 = [];
          this.pdf2 = [];
          this.pdf3 = [];
          this.img5 = [];
          this.pdf5 = [];
          this.ruleForm.urlAddress4 = [];
          this.fileList = [];
          this.detail();
          this.orderList();
        });
    },
    customerPhone(row) {
      if (row.customerPhone !== "——") {
        return utils.formatPhoneNumber(row.customerPhone);
      } else {
        return "——";
      }
    },
    oninput(e) {
      // 通过正则过滤小数点后两位
      e = e.match(/^\d*(\.?\d{0,2})/g)[0] || 0;
      if (e >= 100) {
        this.ruleForm.taxBrokerageRate = 0;
      } else {
        this.ruleForm.taxBrokerageRate = parseInt(e);
      }
      //  payBrokerage 应付金额 ； brokerAmount 申请结佣金额
      this.info.payBrokerage = utils.formatFloat(
        this.info.brokerAmount /
          (1 + parseFloat(this.ruleForm.taxBrokerageRate / 100)),
        2
      ); // 应付款金额
      this.info.taxBrokerage = utils.formatFloat(
        this.info.brokerAmount - this.info.payBrokerage,
        2
      ); // 税金
    },
    openPdf(url) {
      window.open(url);
    },
    // 发票change事件
    billHaveChange(val) {
      if (val == 1) {
        this.isShowBill = true;
      } else {
        this.isShowBill = false;
      }
    },
    dialogPaymentAccount() {
      this.dialogTableVisible = true;
      this.$axios.post(api.SEARCHBANKLIST).then(res => {
        this.paymentCompany = res;
      });
    },
    // 付款公司change
    acountCompanyChange(val) {
      this.account = [];
      this.accountData.payerIdentityNum = "";
      this.PaymentForm.payerAccountId = "";
      let obj = this.paymentCompany.find(item => {
        return item.id === val;
      });
      this.account = obj.bank;
      this.accountData.payerCompany = obj.companyName; // 公司名称
      this.accountData.payerIdentityNum = obj.companyTaxpayer; // 纳税人识别号
      this.accountData.paymentId = obj.id; // 公司id
      this.accountData.paymentCode = obj.companyRelatedCode; // code
    },
    // 账户change
    accountChange(val) {
      this.accountData.payerBranchBankName = "";
      let obj = this.account.find(item => {
        return item.id === val;
      });
      this.accountData.payerAccount = obj.bankAccount; // 账户
      this.accountData.payerBranchBankName = obj.openingBank; // 支行名称
    },
    invoiceChange(val) {
      if (val == 1) {
        this.isIncoiceType = true;
      } else {
        this.isIncoiceType = false;
      }
    },
    // 修改账户提交
    accountSubmitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.info.payerCompany = this.accountData.payerCompany;
          this.info.payerIdentityNum = this.accountData.payerIdentityNum;
          this.info.payerAccount = this.accountData.payerAccount;
          this.info.payerBranchBankName = this.accountData.payerBranchBankName;
          // 没办法（必须得找个中间值代替一下 要不用户修改后没有提交 也会改变数据）
          this.ruleForm.payerCompany = this.accountData.payerCompany;
          this.ruleForm.payerIdentityNum = this.accountData.payerIdentityNum;
          this.ruleForm.payerAccount = this.accountData.payerAccount;
          this.ruleForm.payerBranchBankName = this.accountData.payerBranchBankName;
          this.ruleForm.paymentId = this.accountData.paymentId;
          this.ruleForm.paymentCode = this.accountData.paymentCode;
          this.dialogTableVisible = false;
        }
      });
    },
    accountResetForm(formName) {
      this.ruleForm.paymentId = "";
      this.ruleForm.paymentCode = "";
      this.accountData.payerBranchBankName = "";
      this.accountData.payerIdentityNum = "";
      this.dialogTableVisible = false;
      this.$refs[formName].resetFields();
    },
    // 付款公司查账户
    PaymentCompanyChange(val) {
      this.account = [];
      this.form.regionId = "";
      let obj = this.region.find(item => {
        return item.id === val;
      });
      this.form.areaName = obj.name; // 项目名称
      this.$axios.get(api.REGIONGETREGIONAREA + val).then(res => {
        this.area = res;
      });
    },
    download(url) {
      window.open(url);
    },
    indexFun(index) {
      if (index == 0) {
        return "合计";
      }
      return index;
    },
    orderDetail(orderId) {
      this.$router.push({
        path: "./detailorder",
        query: { orderId: orderId, type: 7 }
      });
    },
    recordsTime(row) {
      return utils.getTimeString(row.createTime);
    },
    auditStatus(status) {
      if (status == 1) {
        return "待审核";
      } else if (status == 2) {
        return "运营审核通过";
      } else if (status == 3) {
        return "财务审核通过";
      } else if (status == 4) {
        return "运营审核拒绝";
      } else if (status == 5) {
        return "财务审核拒绝";
      }
    },
    detail() {
      let id = this.$route.query.id;
      this.$axios
        .get(api.real + id)
        .then(res => {
          console.log(res);
          this.info = res;
          if(!res.financialSettlement){
            this.financeProductInfo = {}
          }else{
            if(this.seeOrToExamine == 1 || !this.role || this.again){
              this.financeProductId = res.financialSettlement.financialProductId
              this.financeProductInfo = res.financialSettlement
              this.bearRate = JSON.parse(res.financialSettlement.bearRate)
            }
          }
          for (let item of JSON.parse(res.urlAddress1)) {
            if (item.type == 0) {
              this.img1.push(item.url);
            } else {
              this.pdf1.push({ name: item.name, url: item.url });
            }
          }
          for (let item of JSON.parse(res.urlAddress2)) {
            if (item.type == 0) {
              this.img2.push(item.url);
            } else {
              this.pdf2.push({ name: item.name, url: item.url });
            }
          }
          for (let item of JSON.parse(res.urlAddress3)) {
            if (item.type == 0) {
              this.img3.push(item.url);
            } else {
              this.pdf3.push({ name: item.name, url: item.url });
            }
          }
          for (let item of JSON.parse(res.entrustedReceipt)) {
            if (item.type == 0) {
              this.img5.push(item.url);
            } else {
              this.pdf5.push({ name: item.name, url: item.url });
            }
          }
          let role = JSON.parse(window.localStorage.getItem("cmsUser"))
            .roleName;
          // 运营人员审核
          if (role == "运营人员" && this.seeOrToExamine == 2) {
            this.ruleForm.billWay = this.info.billWay;
            this.ruleForm.payType = this.info.payType;
            this.ruleForm.taxCalculationWay = this.info.taxCalculationWay;
            this.ruleForm.billHave = this.info.billHave;
            this.ruleForm.billType = this.info.billType;
            this.ruleForm.payNote = this.info.payNote;
            this.ruleForm.taxBrokerageRate = this.info.taxBrokerageRate; // 给税率赋值
            this.ruleForm.receiptType = this.info.receiptType;
            if (this.ruleForm.billHave == 1) {
              this.isShowBill = true;
            }
            for (let item of JSON.parse(res.urlAddress4)) {
              this.fileList.push(item.url);
            }
          } else {
            for (let item of JSON.parse(res.urlAddress4)) {
              if (item.type == 0) {
                this.img4.push(item.url);
              } else {
                this.pdf4.push({ name: item.name, url: item.url });
              }
            }
          }
        })
        .catch(err => {
          console.log(err);
        });
      this.$axios.get(api.record + id).then(res => {
        this.records = res;
        for (let item of res) {
          if (item.system == "H3 BPM系统") {
            if (item.operation == 0) {
              item.operationText = "审核中";
            } else if (item.operation == 1) {
              item.operationText = "审核成功";
            } else {
              item.operationText = "审核失败";
            }
          } else {
            if (item.operatorRoleType == 2) {
              if (item.operation == 1) {
                item.operationText = "待审核";
              } else if (item.operation == 2) {
                item.operationText = "运营审核通过";
              } else if (item.operation == 3) {
                item.operationText = "运营审核拒绝";
              }
            } else if (item.operatorRoleType == 3) {
              if (item.operation == 1) {
                item.operationText = "待审核";
              } else if (item.operation == 2) {
                item.operationText = "财务审核通过";
              } else if (item.operation == 3) {
                item.operationText = "财务审核拒绝";
              }
            }
          }
          // if (item.operatorRoleType == 1) {
          //   item.operatorRoleType = "经纪公司";
          // } else if (item.operatorRoleType == 2) {
          //   item.operatorRoleType = "运营人员";
          // } else if (item.operatorRoleType == 3) {
          //   item.operatorRoleType = "财务人员";
          // }
        }
      });
    },
    orderList() {
      let id = this.$route.query.id;
      this.$axios
        .get(
          `${api.orderlist}${id}/?pageNum=${this.form.pageNum}&limit=${this.form.pageSize}`
        )
        .then(res => {
          for (let item of res.data.list) {
            if (typeof item.comBrokerageProportion === "number") {
              item.comBrokerageProportion = item.comBrokerageProportion + "%";
            }
          }
          this.tableData = res.data.list;
          let obj = res.totalData;
          Object.keys(obj).forEach(val => {
            if (!obj[val]) {
              obj[val] = "——";
            }
          });
          this.tableData.unshift(obj);
          this.total = res.data.total;
        });
    },
    handleSizeChange(size) {
      this.form.pageSize = size;
      this.orderList();
    },
    handleCurrentChange(page) {
      this.form.pageNum = page;
      this.orderList();
    },
    // 重新提交
    againSubmit() {
      this.agree();
    },
    // 驳回
    RejectSubmit() {
      this.ruleForm = {};
      this.req(false);
    },
    // 取消提交
    cancelSubmit() {
      this.$router.go(-1);
    },
    // 同意
    agree() {
      let role = JSON.parse(window.localStorage.getItem("cmsUser")).roleName;
      if (role == "运营人员") {
        this.$refs.upload
          .submit()
          .then(res => {
            let arrs = [];
            for (let item of res) {
              let name = item.substring(item.indexOf("/cms/") + 5, item.length);
              let fileSuffix = item.substring(
                item.lastIndexOf(".") + 1,
                item.length
              );
              let fileType = 0;
              if (fileSuffix == "pdf") {
                fileType = 1;
              } else {
                fileType = 0;
              }
              arrs.push({ name: name, url: item, type: fileType });
            }
            this.ruleForm["urlAddress4"] = JSON.stringify(arrs);
            if(!this.financeProductId && this.ruleForm.payType == 4){
              this.$message({
                message:'融资结算信息不能为空',
                type:'error'
              })
              return 
            }
            this.req(true);
          })
          .catch(err => {
            console.log(err);
          });
      } else {
        let form = {};
        form["taxBrokerage"] = this.info.taxBrokerage;
        form["reason"] = this.reason;
        this.$router.push({
          path: "./applicationAssessment",
          query: { id: this.info.id, type: 7, form: JSON.stringify(form) }
        });
      }
    },
    // 拒绝
    refuse() {
      if (this.reason === "") {
        return this.$message.error("审核理由必填");
      }
      let role = JSON.parse(window.localStorage.getItem("cmsUser")).roleName;
      if (role == "运营人员") {
        this.ruleForm = {};
        this.req(false);
      } else {
        this.ruleForm = {};
        this.ruleForm.taxBrokerage = this.info.taxBrokerage;
        this.req(false);
      }
    },
    req(bool) {
      this.ruleForm.auditStatus = bool;
      this.ruleForm.applyId = this.info.id;
      this.ruleForm.reason = this.reason;
      let params = {}
      params = this.ruleForm
      // 融资信息参数
      if(this.ebillCheck){
        params.financialSettlement = {}
        let financialSettlement = {}
        financialSettlement.financialAmount = this.financeProductInfo.financialAmount
        financialSettlement.financialProductId = this.financeProductInfo.financialProductId
        financialSettlement.financialProductName = this.financeProductInfo.financialProductName
        financialSettlement.interestRate = this.financeProductInfo.interestRate
        financialSettlement.easylifeRate = this.financeProductInfo.easylifeRate
        financialSettlement.availableAmount = this.financeProductInfo.availableAmount
        financialSettlement.interest = this.financeProductInfo.interest
        financialSettlement.principalAndInterest = this.financeProductInfo.principalAndInterest
        financialSettlement.acctPeriod = this.financeProductInfo.acctPeriod
        financialSettlement.repayDate = this.financeProductInfo.repayDate
        financialSettlement.billPayType = this.financeProductInfo.billPayType
        financialSettlement.bearRate = this.financeProductInfo.bearRate
        params.financialSettlement = financialSettlement
      }
      this.$axios.post(api.companyAudit, params).then(res => {
        this.$message({
          type: "success",
          message: "操作成功"
        });
        this.$router.push({ path: "./brokerCompany" });
      });
    }
  }
};
</script>
<style lang="stylus">
.brokerCompanyDetail {
  .moneyInfo{
    margin-top:20px;
  }
  .financingInfo{
    margin-right:20px;
    font-weight:700;
    // cursor:pointer;
  }
  .moneyInfo-color{
    color:#409EFF;
  }
  .moneyInfo table{
    border:1px solid #ccc;
    font-size:15px;
    border-collapse: collapse;
    width: 60%;
    border-spacing:0px;
  }
  .moneyInfo tr td{
    border: 1px solid #ccc;
    line-height: 35px;
  }
  .td-name {
    width:35%;
    text-align: center;
  }
  .td-content {
    text-align:left;
    padding:0 0 0 30px;
    box-sizing:border-box;
  }
  .td-contentName{
    display:flex;
  }
  .td-contentName div:nth-child(1){
    flex:7;
  }
  .td-contentName div:nth-child(3){
    flex:7;
  }
  .minddle{
    flex:2;
  }
  .td-contentName p,.td-contentName p{
    margin:0;
    padding:0;
    // line-height:20px;
  }
  .item-group {
    padding-left: 15px;
    font-size: 14px;
  }

  .item table {
    font-size: 15px;
    border-collapse: collapse;
    width: 100%;
    margin: 0 auto;
  }

  .item table tr td {
    border: 1px solid #ccc;
    line-height: 30px;
    box-sizing: border-box;
    padding: 0 3px;
    text-align: center;
    width: 16.6%;
  }

  .item table tr td:nth-child(odd) {
    background: #f2f2f2;
  }

  .item-group img {
    margin-right: 15px;
    max-width: 250px;
    max-height: 250px;
  }

  .textTitle {
    line-height: 40px;
    font-weight: bold;
    margin-top: 15px;
  }

  .AudiReason {
    position: relative;
  }

  .resasonNum {
    position: absolute;
    bottom: 60px;
    right: 12px;
    color: #666;
  }

  .technologicalProcess {
    font-size: 14px;
    width: 60%;
    margin: 0 auto;
  }

  .fileStyle {
    margin: 20px 0px;
  }
  .pdfStyle li {
    line-height:40px;
  }

  .Payment {
    color: #409EFF;
    cursor: pointer;
    position: absolute;
    right: 15px;
    top: -5px;

    i {
      margin-right: 5px;
    }
  }
}

.el-tabs__nav-wrap::after {
  background-color: #fff !important;
}

.el-tabs__item {
  font-weight: bold;
  font-size: 16px;
}
</style>

